import { PokerHand } from "./PokerHand.js";
import { PokerCard } from "../PokerCard.js";
import { ErrorPokerHand } from "./ErrorPokerHand.js";
import { RocketPokerHand } from "./RocketPokerHand.js";
export type { PokerCard, PokerType } from "../PokerCard.js";

/** 炸弹类型 */
export class BombPokerHand extends PokerHand {
  public value: number;
  constructor(cards: PokerCard[]) {
    super(cards);

    this.value = cards[0].value;
  }
  /**
   * 判断是否为炸弹：四张同数值牌（如四个 7 ）。
   * @param cards 手牌
   * @returns
   */
  public static isStandard(cards: PokerCard[]) {
    const str = cards.map((card) => card.letter).join("");
    return /^([A-O])\1{3}$/g.test(str);
  }
  public isStandard = BombPokerHand.isStandard;
  public isBetter(target: PokerHand): boolean {
    if (target instanceof ErrorPokerHand) {
      return false;
    }

    if (target instanceof RocketPokerHand) {
      return false;
    }

    if (target instanceof BombPokerHand) {
      return this.value > target.value;
    }

    return true;
  }
}

export default BombPokerHand;
